import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import viteCompression from 'vite-plugin-compression'

import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import VueJsx from '@vitejs/plugin-vue-jsx'
import { viteCommonjs } from '@originjs/vite-plugin-commonjs'
// https://vite.dev/config/
export default defineConfig({
  //设置scss的api类型为modern-compiler
  css: {
    preprocessorOptions: {
      scss: {
        api: 'modern-compiler'
      }
    }
  },
  plugins: [
    VueJsx(),
    vue(),
    vueDevTools(),
    viteCompression({
      deleteOriginFile: false,
      threshold: 10240,
      algorithm: 'gzip',
      ext: '.gz'
    }),

    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    }),
    viteCommonjs()
  ],
  server: {
    host: '0.0.0.0',
    port: 8848,
    proxy: {

      '/dao/ABGDP鲍曼不动杆菌智能计算平台/image': {
        // target: 'http://219.216.104.147:8081',
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        rewrite: (path) => {
          const decodedPath = decodeURIComponent(path);
          return decodedPath.replace(/^\/dao\/ABGDP鲍曼不动杆菌智能计算平台/, '');
        }
      },

      '/dao/image': {
        // target: 'http://219.216.104.147:8081',
        target: 'http://127.0.0.1:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dao/, '')
      },
      '/session/listdao/image': {
        // target: 'http://219.216.104.147:8081',
        target: 'http://localhost:8081',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/session\/listdao/, '')
      },
      '/image': {
        target: 'http://localhost:8081',
        changeOrigin: true,
      },
    }
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
    extensions: ['.js', '.vue']
  },
  assetsInclude: ['**/*.wasm'],
  optimizeDeps: {
    exclude: ['@rdkit/rdkit']
  },
})
